import * as THREE from 'three'
import { EventEmitter } from 'events'
export default class Time extends EventEmitter {
    static UPDATE_EVENT = 'update'

    clock = null;
    previousTime = 0;
    deltaTime = 0;
    constructor() {
        super();

        this.clock = new THREE.Clock();
        this.previousTime = 0;


        this.update()
    }
    update() {
        const elapsedTime = this.clock.getElapsedTime();
        this.deltaTime = elapsedTime - this.previousTime;
        this.previousTime = elapsedTime;

        this.emit(Time.UPDATE_EVENT)
        window.requestAnimationFrame(() => this.update())
    }
}